// miniprogram/components/scoring/result.js
const app = getApp()
Component({



  properties: {



    playerorteam: {
      type: String,
      value: "0"
    },

    // 这里定义了id属性，属性值可以在组件使用时指定
    selectid: {
      type: Number,
      value: 0
    },
    matchinfo: {
      type: Object,
      value: undefined,
      observer: function (newVal, oldVal) {

        this._matchinfopropertyChange(newVal, oldVal);

      } // 属性被改变时执行的函数（可选），也可以写成在methods段中定义的方法名字符串, 如：'_propertyChange'

    },
    matchleaders: {
      type: Object,
      value: undefined,
      observer: function (newVal, oldVal) {
        this._matchleaderspropertyChange(newVal, oldVal);
      } // 属性被改变时执行的函数（可选），也可以写成在methods段中定义的方法名字符串, 如：'_propertyChange'

    },
    awards: {
      type: Object,
      value: undefined,
      observer: function (newVal, oldVal) {
       // this._awardspropertyChange(newVal, oldVal);
      } // 属性被改变时执行的函数（可选），也可以写成在methods段中定义的方法名字符串, 如：'_propertyChange'

    },

  },
  /**
   * 页面的初始数据
   */
  data: {
    staticUrl: app.globalData.staticUrl,
    matchinfo: undefined,
    currentpageheight: 0, //设置高度
    currentTab: 0,
    selectplayerid: undefined,
    selectteamid: undefined,
    teamorplayer: 0, //0为个人1为team
    top:99,
    istopnav:false,

  },

  



  /**
   * 组件的方法列表
   * 更新属性和数据的方法与更新页面数据的方法类似
   */
  methods: {

    openawardercard:function(e){
        let {item} =  e.currentTarget.dataset;
        if(item.isteam){
          e.currentTarget.dataset.id=item.tm_id;
          e.currentTarget.dataset.teamname = item.bj;
          this._openteamCard(e);
        }
        else{
          e.currentTarget.dataset.id=item.pl_id;
          this._openplayerCard(e);
        }
    },
    //打开playerscorecard 页面 
    _openplayerCard(e) {
      this.setData({
        selectplayerid: e.currentTarget.dataset.id,
        teamorplayer: 0
      });
      var playername = e.currentTarget.dataset.playername;
      let id = (this.data.teamorplayer == 0) ? this.data.selectplayerid : this.data.selectteamid;
      // 微信小程序中是通过triggerEvent来给父组件传递信息的
      this.triggerEvent('_openplayerCard', {
        playerorteam: this.data.teamorplayer,
        selectid: id,
        playername: playername,
        matchinfo: JSON.stringify(this.data.matchinfo)
      }) // 将参数的形式传递给父组件

    },

    _awardspropertyChange:function (newVal, oldVal) {

      this.setData({
        awards: newVal
      });

    },
    
    _openteamCard:function(e){
      console.log(e);
      this.setData({
        selectteamid: e.currentTarget.dataset.id,
        teamorplayer: 0
      });
      var teamname = e.currentTarget.dataset.teamname;
      let id =e.currentTarget.dataset.id;
      // 微信小程序中是通过triggerEvent来给父组件传递信息的
      this.triggerEvent('_openteamCard', {
        
        selectid: id,
        teamname: teamname,
        matchinfo: JSON.stringify(this.data.matchinfo)
      }) // 将参数的形式传递给父组件
    },

    _matchinfopropertyChange: function (newVal, oldVal) {

      this.setData({
        matchinfo: newVal
      });

    },

    _matchleaderspropertyChange: function (newVal, oldVal) {
      this.fillheight();

    },

    ///填充swiper的高度，它不能自适应
    fillheight: function () {

      var that = this;
      var obj = this.createSelectorQuery().select("#vscoring" + that.data.currentTab);

      obj.boundingClientRect(function (rect) {
       
        if (rect == null || rect.height == null) {
          return;
        }
        console.log(rect.height);
        that.setData({
          currentpageheight:rect.height  // 节点的高度
        });
      
        
      }).exec();
    },

    //  tab切换逻辑
    swichNav: function (e) {
      var that = this;
      if (that.data.currentTab === e.target.dataset.current) {

        return false;
      } else {
        that.setData({
          currentTab: e.target.dataset.current
        })

        that.fillheight();
      }
    },

    bindChange: function (e) {
      var that = this;
      that.setData({
        currentTab: e.detail.current
      });
      that.fillheight();
    },

    scrollTop(e){
      let that = this;
      if(e.detail.scrollTop<=0 && that.data.istopnav){
        that.setData({
          istopnav: false
          })

          console.log(e.detail.scrollTop);
      }
      else{
        console.log(" istopnav true");
      }

    },
    //控制回到顶部按钮的显示与消失
    _scrollTopFun(e) {
      let that = this;

      var objtitle = that.createSelectorQuery();
      objtitle.select("#vscoring" + that.data.currentTab).boundingClientRect(function (rect) {
       
        var top = rect.top;
        console.log(top);
        if (top <= 0) {
          that.setData({
            istopnav: true
          })

        } else {
          that.setData({
            istopnav: false
          })
        }
      }).exec();

    }



  },


})